<template>
  <div id="safe_audit">
    <p>页面数据的百分比:<el-progress :text-inside="true"  :stroke-width="24" :percentage="max" status="success"></el-progress></p>
    <h2 style="text-align: center">制定出库单</h2>
    <!--    入库管理-->
    <el-table :data="arrList1" style="width: 100%">
      <el-table-column prop="orderId" label="订单id" width="150">
      </el-table-column>
      <el-table-column prop="orderNumber" label="订单编号" width="150">
      </el-table-column>
      <el-table-column prop="consumerId" label="下单用户id" width="150">
      </el-table-column>
      <el-table-column prop="merchantId" label="商户id" width="150">
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总价" width="150">
      </el-table-column>
      <!--操作列-->
      <el-table-column label="出库调度" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showById(scope.row.orderId)" round>出库申请</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 出库调度弹出对话框 -->
    <el-dialog title="出库调度" :visible.sync="dialogVisible" width="60%">
      <el-form :inline="true" :model="filebean" class="demo-form-inline">
        <el-form-item label="出库单编号">
          <el-input v-model="filebean.orderId" placeholder="订单id"></el-input>
        </el-form-item>
        <el-form-item label="仓库id">
          <el-input v-model="filebean.orderNumber" placeholder="订单编号"></el-input>
        </el-form-item>
        <el-form-item label="入库人">
          <el-input v-model="filebean.consumerId" placeholder="下单用户id"></el-input>
        </el-form-item>
        <el-form-item label="总数量">
          <el-input v-model="filebean.totalAmount" placeholder="总数量"></el-input>
        </el-form-item>
        <el-form-item label="总价格">
          <el-input v-model="filebean.totalPrice" placeholder="总价格"></el-input>
        </el-form-item>
        <el-form-item label="出库人">
          <el-input v-model="filebean.payer" placeholder="出库人"></el-input>
        </el-form-item>
        <el-form-item label="审核人">
          <el-input v-model="filebean.checker" placeholder="审核人"></el-input>
        </el-form-item>
        <el-form-item label="出库理由">
          <el-input v-model="filebean.reason" placeholder="出库理由"></el-input>
        </el-form-item>
        <el-form-item label="审核理由">
          <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入审核理由"
              v-model="filebean.checkReason">
          </el-input>
        </el-form-item>
<!--         <el-form-item label="创建时间">-->
<!--        <el-input v-model="filebean.createdTime" class="demo-ruleForm" autocomplete="off" readonly></el-input>-->
<!--      </el-form-item>-->
      </el-form>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            prop="productId"
            label="商品id"
            width="180">
        </el-table-column>
        <el-table-column
            prop="ordersId"
            label="所属订单id"
            width="180">
        </el-table-column>
        <el-table-column
            prop="amount"
            label="数量"
            width="180">
        </el-table-column>
        <el-table-column
            prop="price"
            label="单价">
        </el-table-column>
        <el-table-column
            prop="subtotal"
            label="小计">
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>

    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  created() {
    this.list()
  },
  data() {
    return {
      arrList1: [],
      tableData: [],
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleCheck: false,
      dialogVisibleAdd: false,
      // 审核表单的对象
      addForm: {

      },
      //定义到对话框的值
      filebean: {

      },
      showGather: {

      },
      payList: {},
      max:0,
      createdTime:"",
      payAry: {},
    }
  },
  methods: {

    async list() {
      const { data: res } = await this.$http.post
      (`/community/pay/show2/${this.currentPage}/${this.pageSize}`)
      this.arrList1 = res.rows
      this.total = res.total
      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    // async table() {
    //   // let row;
    //   const res = await this.$http.get
    //   //gatherDetailsById
    //   (`/community/payDetails/show3`)
    //   console.log('res+++table',res)
    //   //rows
    //   this.tableData = res.data
    // },
    // async showById(index, row) {
    //     this.dialogVisible = true;
    //     const { data: res } = await this.$http.post(`/community/pay/showById2?orderId=${row.orderId}`);
    //     console.log('res',res)
    //     this.filebean = res;
    //
    //     const {data:ses} = await this.$http.post
    //     (`/community/gather/purchaseOrderById?id=`+id)
    //     this.tableData = ses
    // },
    async showById(id) {
      this.dialogVisible = true;
      const { data: res } = await this.$http.post(`/community/pay/showById2?orderId=`+id);
      this.filebean = res;

      const {data:ses} = await this.$http.post
      (`/community/pay/OrderById?id=`+id)
      this.tableData = ses
    },
    //修改
    // async edit() {
    //   //拿到仓库id
    //   let stockId = this.stockId
    //   let totalAmount = this.filebean.totalAmount
    //   let parameter = {
    //     stockId,
    //     totalAmount
    //   }
    //   this.getdatatime()
    //   const { data: res } = await this.$http.post
    //   (`/community/pay/updateTWO2`,parameter)
    //   alert("出库申请成功")
    // },
    //制定入库单与入库申请单
    async edit(){
      console.log(this.filebean)
      // console.log(this.tableData)
      this.payList.payer = this.filebean.payer
      this.payList.reason = this.filebean.reason
      this.payList.totalAmount = this.filebean.totalAmount
      this.payList.totalPrice = this.filebean.totalPrice
      // this.payList.purchaseId = this.filebean.purchaseId
      // this.payList.supplierId = this.filebean.supplierId

      const pay=this.payList
      const details=this.tableData
      this.payAry = {
        pay,
        details
      }
      const { data: res } =
          await this.$http.post(`/community/pay/add2`,payAry);
          this.list()

      //改为已收货
      console.log(this.payList)
      const orderId = this.arrList1[0].orderId
      console.log(orderId)
      //修改采购单的发货状态
      const { data: ses } =
          await this.$http.post(`/community/pay/updateById?id=`+orderId);

      //将已添加过入库单与入库明细单的数组设为空
      this.payArys = {}
      //隐藏入库面板
      this.dialogVisible = false;
      this.list()
    },
    getdatatime() {
      var dt = new Date();
      var y = dt.getFullYear();
      var m = (dt.getMonth() + 1).toString().padStart(2, '0');
      var d = dt.getDate().toString().padStart(2, '0');
      var hh = dt.getHours().toString().padStart(2, '0');
      var mm = dt.getMinutes().toString().padStart(2, '0');
      var ss = dt.getSeconds().toString().padStart(2, '0');
      this.checkTime = `${y}-${m}-${d} ${hh}:${mm}:${ss}`
    },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
  },
  // 表单查询
  search() {
    // 查询
    this.currentPage = 1
    this.list()
  },
  check() {
    // 获取当前时间
    const now = new Date();
    // 格式化当前时间
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const day = String(now.getDate()).padStart(2, '0');
    const hours = String(now.getHours()).padStart(2, '0');
    const minutes = String(now.getMinutes()).padStart(2, '0');
    const seconds = String(now.getSeconds()).padStart(2, '0');
    // 设置 addForm.checkTime 为当前时间
    this.addForm.checkTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    // 其他逻辑...
  },
}
</script>

<style></style>